package com.example.excise06.service.impl;

import com.example.excise06.entity.UserEntity;
import com.example.excise06.repository.UserRepository;
import com.example.excise06.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {
    private final UserRepository userRepository;

    public UserServiceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public UserEntity updateUserHeader(String login, String headImage) {
        //1.根据用户名查找账户数据对象
        Optional<UserEntity>
                userEntityaOptional=this.userRepository.findByLogin(login);
        //2.判断账户是否存在
        if (userEntityaOptional.isPresent()){
            UserEntity userEntity=userEntityaOptional.get();
            //3.赋值账户头像字段
            userEntity.setHeadImage(headImage);
            userEntity=userRepository.save(userEntity);
            return userEntity;
        }
        return null;
    }
}